package pub.guoxin.oops.auth.vo;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import pub.guoxin.oops.enums.Authority;
import pub.guoxin.oops.model.User;
import pub.guoxin.oops.tidy.LocalDateDeserializer;
import pub.guoxin.oops.tidy.LocalDateSerializer;
import pub.guoxin.oops.tidy.LocalDateTimeDeserializer;
import pub.guoxin.oops.tidy.LocalDateTimeSerializer;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserVo {

    private String id;
    /**
     * 公司Id
     */
    @ApiModelProperty(value = "公司Id", required = true, hidden = true)
    private String companyId;

    @NotNull
    @Size(min = 2, max = 50)
    @ApiModelProperty(value = "姓", required = true, hidden = true)
    private String name;

//    @Email
//    @NotNull
//    @Size(min = 4, max = 50)
//    @ApiModelProperty(value = "邮箱", required = true, hidden = true)
//    private String email;

    @NotNull
    @Size(min = 11, max = 11)
    @ApiModelProperty(value = "手机号", required = true, hidden = true)
    private String username;

    @ApiModelProperty(value = "权限", required = true, hidden = true)
    private List<Authority> authorities = Lists.newArrayList();

    @ApiModelProperty(value = "创建时间", required = true, hidden = true)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    private LocalDateTime creation;

    public UserVo(User user) {
        this.id = user.getId();
        this.authorities = user.getAuthorities();
        this.companyId = user.getCompanyId();
        this.name = user.getFirstname();
        this.username = user.getMobile();
        this.creation = user.getCreation();
    }

}
